package com.txw.hellojkxy;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class MainActivity extends Activity {

    private static final String TAG = "MainActivity";

    private TextView txtReceive;
    private Button btnReceive;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        EventBus.getDefault().register(MainActivity.this);

        txtReceive= (TextView) findViewById(R.id.txt_receive);
        btnReceive= (Button) findViewById(R.id.btn_receive);

        btnReceive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent=new Intent(MainActivity.this,SecondActivity.class);
                startActivity(intent);

            }
        });

    }

    /**
     * 注册监听事件
     * @param messageEvent
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void showMessage(MessageEvent messageEvent){
        txtReceive.setText("接收到的信息为：\n"+messageEvent.getName());
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();

        EventBus.getDefault().unregister(MainActivity.this);

    }
}
